package copyengine.ui.component.panel
{
	import flash.display.DisplayObject;
	import flash.geom.Rectangle;

	public final class CEAutoResizeableVPanel extends CEVPanelBasic
	{
		private var panelBgMc:DisplayObject;

		private var panelBgborder:int;

		public function CEAutoResizeableVPanel(_panelBgMc:DisplayObject, _vGap:int = 0, _border:int = 0)
		{
			panelBgborder = _border;
			panelBgMc = _panelBgMc;
			super(_vGap);
		}

		override protected function doInitialize():void
		{
			panelBgMc && panelBgContainer.addChild(panelBgMc);
		}

		override protected function onPanelDispose():void
		{
			panelBgMc = null;
		}

		override protected function onFinishedLaytoutSubElement():void
		{
			if (panelBgMc)
			{
				panelBgMc.width = panelContainer.width + panelBgborder * 2;
				panelBgMc.height = panelContainer.height + panelBgborder * 2;
			}
			//因为panelBg就以panel的0.0点对齐,所以只要偏移left的距离即可
			//实际是偏移0-left
			var rc:Rectangle = panelBgContainer.getRect(this);
			panelBgContainer.x = -rc.left - panelBgborder;
			panelBgContainer.y = -rc.top - panelBgborder;
		}

	}
}
